package cn.wostore.wxhelper.Xposed;

import android.view.ContextMenu;
import android.view.View;
import cn.wostore.wxhelper.Xposed.LoadHook;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

/**
 * @author wuch
 * @date 2018/12/21 0021
 */
public class MyContextMenuListener implements View.OnCreateContextMenuListener {
    final LoadHook loadHook;
    private final View.OnCreateContextMenuListener onCreateContextMenuListener;
    final XC_MethodHook.MethodHookParam methodHookParam;

    public MyContextMenuListener(LoadHook loadHook, View.OnCreateContextMenuListener onCreateContextMenuListener, XC_MethodHook.MethodHookParam param) {
        this.loadHook = loadHook;
        this.onCreateContextMenuListener = onCreateContextMenuListener;
        this.methodHookParam = param;
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        this.onCreateContextMenuListener.onCreateContextMenu(menu, v, menuInfo);
        int position = XposedHelpers.getIntField(v.getTag(), "position");
        Object item = XposedHelpers.getObjectField(methodHookParam.thisObject, "vBe");
        Object info = XposedHelpers.getObjectField(item, "bFH");
        String str = (String) XposedHelpers.getObjectField(info, "field_imgPath");
        int filedType = XposedHelpers.getIntField(info, "field_type");
        XposedBridge.log(str + "类型" + filedType);
        if (filedType == 34) {
            menu.add(position, 1001, 0, "哈哈哈");
            Object view = XposedHelpers.getObjectField(methodHookParam.thisObject, "vko");
            Object view1 = XposedHelpers.getObjectField(view, "vtz");
            this.loadHook.a(view1, str);
        }


    }
}
